﻿namespace DesignPatterns.SingletonPattrens
{
    /// <summary>
    /// 静态内部类单例模式，线程安全
    /// </summary>
    public class StaticSingleton
    {
        private class InnerInstance
        {
            /// <summary>
            /// 当一个类有静态构造函数时，它的静态成员变量不会被beforefieldinit修饰
            /// 就会确保在被引用的时候才会实例化，而不是程序启动的时候实例化
            /// </summary>
            static InnerInstance() { }
            internal static StaticSingleton instance = new StaticSingleton();
        }
        private StaticSingleton()
        {
        }
        public static StaticSingleton getInstance()
        {
            return InnerInstance.instance;
        }
    }
}
